package org.linlinjava.litemall.wx.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import lombok.RequiredArgsConstructor;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.dao.LitemallNoticeMapper;
import org.linlinjava.litemall.db.domain.LitemallNotice;
import org.linlinjava.litemall.db.dto.WxMsgTypeDTO;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;

@Service
@RequiredArgsConstructor
public class WxMsgService {

    private final LitemallNoticeMapper litemallNoticeMapper;


    public ResponseUtil.Response systemMsg(Integer userId, Integer page, Integer limit,String type) {
        //PageHelper.startPage(page, limit);
        List<LitemallNotice> litemallNotices = litemallNoticeMapper.selectList(Wrappers.lambdaQuery(LitemallNotice.class)
                .eq(LitemallNotice::getUserId,userId)
                .in(LitemallNotice::getType, Arrays.asList(type.split(",")))
                .eq(LitemallNotice::getDeleted,0)
                .orderByDesc(LitemallNotice::getAddTime)
                );
        return ResponseUtil.okPageInfo(litemallNotices);
    }

    public ResponseUtil.Response msgType(Integer userId) {
        List<WxMsgTypeDTO> list = litemallNoticeMapper.allTypesByuser(userId);
        return ResponseUtil.success(list);
    }

    public ResponseUtil.Response recentlyList(Integer userId, Integer page, Integer limit) {
        //PageHelper.startPage(page,limit);
        List<LitemallNotice> litemallNotices = litemallNoticeMapper.selectList(Wrappers.lambdaQuery(LitemallNotice.class)
                .eq(LitemallNotice::getUserId,userId)
                .eq(LitemallNotice::getDeleted,0));
        return ResponseUtil.okPageInfo(litemallNotices);
    }
}
